package com.xsjl.base.service;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xsjl.base.mapper.LabelMapper;
import com.xsjl.base.pojo.Label;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName LabelService
 * @Description TODO
 * @Author PRETEXT
 * @Date2020/2/27 20:11
 * @Version V1.0
 **/
@Service
public class LabelService {
    @Autowired
    private LabelMapper labelMapper;
    public void saveLabel(Label label) {
        labelMapper.insert(label);
    }

    public void updateLabel(Label label) {
        labelMapper.updateById(label);
    }

    public List<Label> findAllLabel() {
        return labelMapper.selectList(null);
    }

    public Label findById(String id) {
        return labelMapper.selectById(id);
    }

    public void deleteById(String id) {
        labelMapper.deleteById(id);
    }

    /**
     * 根据条件查询列表
     * @return
     */
    public List<Label> findLabelList(Label label) {
        QueryWrapper<Label> wrapper = new QueryWrapper<>();
        wrapper.like(StringUtils.isNotBlank(label.getLabelname()), "labelname", label.getLabelname())
                .like(StringUtils.isNotBlank(label.getState()), "state", label.getState())
                .like(label.getCount() != 0, "count", label.getCount())
                .like(StringUtils.isNotBlank(label.getRecommend()), "recommend", label.getRecommend());
        return labelMapper.selectList(wrapper);
    }

    public Page<Label> pageQuery(int page, int size) {
        Page<Label> pages = new Page<>(page, size);
        Page<Label> labels = labelMapper.selectPage(pages, null);
        return labels;
    }


}
